<?php namespace App\Http\Requests;

use App\Http\Requests\Request;
use Validator;
use App\Project;

class ProjectRequest extends Request {

	/**
	 * Determine if the user is authorized to make this request.
	 *
	 * @return bool
	 */
	public function authorize()
	{
		return true;
	}

    public function attributes()
    {
        return [
            'project_name'      =>   '项目名字' ,
            'project_intro'     =>   '项目介绍' ,
            'company_name'      =>   '公司名字' ,
            'field_id'          =>   '投资领域' ,
            'phase_id'          =>   '投资阶段' ,
            'project_lightspot' =>   '项目亮点' ,
            'project_desc'      =>   '项目描述' ,
            'project_future'    =>   '项目前景' ,
            'project_tags'      =>   '项目标签',
            'invet'             =>   '融资金额',
            'sell_stock'        =>   '出让股权',
            'min_money'         =>   '最小额度',
            'invest_num'        =>   '投资数量',
            'phone'             =>   '联系方式',
            'name'              =>   '联系人',
            'email'             =>   '联系邮箱',
            'project_url'       =>   '项目链接',
            'star_layer'        =>   '项目指数',
        ];
    }

	/**
	 * Get the validation rules that apply to the request.
	 *
	 * @return array
	 */
	public function rules()
	{
		return [
            'project_name'      =>   'max:255' ,
            'project_intro'     =>   '' ,
            'company_name'      =>   '' ,
            'field_id'          =>   '' ,
            'phase_id'          =>   '' ,
            'project_lightspot' =>   '' ,
            'project_desc'      =>   '' ,
            'project_future'    =>   '' ,
            'project_tags'      =>   '',
            'invet'             =>   '',
            'sell_stock'        =>   '',
            'min_money'         =>   '',
            'invest_num'        =>   '',
            'phone'             =>   '',
            'name'              =>   '',
            'email'             =>  'email',
            'project_url'       =>   'url',
            'star_layer'        =>   'max:5',
        ];
	}


    /**
     * @param $projectName      项目名字已经存在
     * @return bool
     */
    public static function ProjectNameExists($projectName)
    {
        if(Project::whereProjectName($projectName)->exists())
            return true;
        return false;
    }

    /**
     * @param $str              手机号码格式错误
     * @return mixed
     */
    public static function isPhone($str)
    {
        return Validator::make(['phone' => $str], ['phone' => ['regex:/1\d{10}/']])->passes();
    }


}
